package com.briup.jz.web.controller;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.jz.bean.Comment;
import com.briup.jz.bean.extend.CommentExtend;
import com.briup.jz.service.ICommentService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(description="评论文章相关接口")
@RestController
@RequestMapping("/comment")


public class CommentController {
	@Autowired
    private ICommentService commentService;

    @ApiOperation(value = "级联查询所有评论")
    @GetMapping("queryCascade")
    public Message queryCascade(Long articleId,String comment,String reply,String status,Long userId){
        List<CommentExtend> list = commentService.queryCascade(articleId,comment,reply,status,userId);
        return MessageUtil.success(list);
    }
    
    
    
    @ApiOperation(value = "查询所有评论")
    @GetMapping("query")
    public Message query(Long articleId,String comment,String reply,String status,Long userId){
        List<Comment> list = commentService.query(articleId,comment,reply,status,userId);
        return MessageUtil.success(list);
    }

    @ApiOperation(value = "通过id删除")
    @GetMapping("deleteById")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
    })
    public Message deleteById(@NotNull Long id){
    	commentService.deleteBy(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "保存或更新评论信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "主键",paramType = "form"),
            @ApiImplicitParam(name="comment",value = "评论",paramType = "form",required = true),
            @ApiImplicitParam(name="comment_time",value = "评论时间",paramType = "form"),
            @ApiImplicitParam(name="reply",value = "回复",paramType = "form"),
            @ApiImplicitParam(name="reply_time",value = "回复时间",paramType = "form"),
            @ApiImplicitParam(name="status",value = "状态",paramType = "form"),
            @ApiImplicitParam(name="user_id",value = "用户id",paramType = "form"),
            @ApiImplicitParam(name="article_id",value = "文章编号",paramType = "form"),
            @ApiImplicitParam(name="parent_id",value = "父栏目id",paramType = "form"),
    })
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Comment comment){
    	commentService.saveOrUpdate(comment);
        return MessageUtil.success("更新成功");
    }
    
}
